class PubSub {
    constructor() {
        this.eventMap = {

        }
    }
}
//发布
publish(eventName, value) {
    const eventArr = this.eventMap[eventName]
    if (eventArr) {
        eventArr.forEach(callback => {
            callback(eventName, value)
        })
    }
}

//订阅
// 订阅
subscribe(eventName, callback) {
    if (!this.eventMap[eventName]) {
        this.eventMap[eventName] = [];
    }
    this.eventMap[eventName].push(callback);
    return {
        eventName,
        callback
    };
}
//移除订阅
unsubscribe({ eventName, callback }){
    this.eventMap[eventName] = this.eventMap[eventName].filter(cb => cb !== callback)
}
export default new PubSub();